package com.lagou.controller;


import com.lagou.domain.Dept;
import com.lagou.domain.Employee;
import com.lagou.service.DeptService;
import com.lagou.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    private EmpService empService;

    @Autowired
    private DeptService deptService;

    /**
     * 查询所有员工信息
     * @param model
     * @return
     */
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Employee> list = empService.findAll();
        model.addAttribute("list",list);
        return "emp";
    }

    /**
     * 添加新员工
     * @param employee
     * @return
     */
    @RequestMapping("/save")
    public String save(Employee employee) {
        System.out.println(employee);
        empService.save(employee);
        return "redirect:/emp/findAll";
    }

    /**
     * 异步查询部门信息
     * @return
     */
    @RequestMapping(value = "/ajaxRequest")
    @ResponseBody
    public List<Dept> ajaxRequest() {
        List<Dept> list = deptService.findAll();
        return list;
    }

}
